package com.sanchunhui.psc.ui.activity

import android.os.Bundle
import android.view.View
import com.sanchunhui.psc.R
import com.sanchunhui.psc.common.BaseApplication
import com.sanchunhui.psc.injection.component.DaggerProjectTeamComponent
import com.sanchunhui.psc.injection.module.ProjectTeamModule
import com.sanchunhui.psc.presenter.SetTeamInfoPresenter
import com.sanchunhui.psc.presenter.view.SetTeamInfoView
import com.sanchunhui.ui.activity.BaseMvpActivity
import kotlinx.android.synthetic.main.activity_team_set_info.*
import org.jetbrains.anko.toast

/**
 * @Author zyx
 * @Date 2021/5/11-9:47
 * @Dscribe
 */
class SetTeamInfoActivity : BaseMvpActivity<SetTeamInfoPresenter>(), SetTeamInfoView, View.OnClickListener{


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_team_set_info)
        processIntent()
        ib_back.setOnClickListener(this)
        iv_done.setOnClickListener(this)
    }

    private lateinit var teamId  : String
    private fun processIntent() {
        if (intent.hasExtra("teamId")) {
            teamId = intent.getStringExtra("teamId")
        }
    }


    override fun injectComponent() {
        DaggerProjectTeamComponent.builder().activityComponent(mActivityComponent).projectTeamModule(
            ProjectTeamModule()
        ).build().inject(this)
        mPresenter.mView = this
    }

    override fun onSetTeamInfoResult(result: Boolean) {
        toast("修改小组名成功")
        finish()
    }

    override fun onClick(v: View?) {
        when(v?.id) {
            R.id.ib_back -> finish()
            R.id.iv_done -> {
                val user = BaseApplication.mUser
                mPresenter.setTeamInfo(teamId.toInt(),user.token.toString(),et_name.text.toString())
            }
        }
    }

}